import urllib2
from bs4 import BeautifulSoup
from urllib2 import HTTPError

url = "https://www.baidu.com/"
url2 = "https://movie.douban.com/top250"

if __name__ == "__main":
    try:
        response = urllib2.urlopen(url2).read()
    except HTTPError as e:
        print e
    else:
        content = BeautifulSoup(response, "html.parser")
        try:
            titles = content.select("[class~=title]")
            # for title in titles:
            #     print title.string
            print content.find_all("a",{"class":"nav-login"})
        except AttributeError as e:
            print e